package com.wlb.test.service.rabbitmq.publish;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.wlb.test.util.rabbitmq.ConnectionUtil;
import com.wlb.test.util.rabbitmq.QueueEnum;

/**
 * @Author:wanglibing
 * @Mail:wanglibing@jd.com
 * @Date:Created in 14:12 2018/1/30
 * @Description:
 */
public class Send {
    public static void main(String[] args) throws Exception{
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();
//          发送端直接发到交换机上
        channel.exchangeDeclare(QueueEnum.EXCHANGE_NAME.getName(),"fanout");
        // 消息内容
        String message = "id=1111";
        channel.basicPublish(QueueEnum.EXCHANGE_NAME.getName(), "", null, message.getBytes());
        System.out.println(" [x] Sent '" + message + "'");
        channel.close();
        connection.close();
    }
}
